package com.ly.lw.styledo.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.ly.lw.styledo.R;
import com.ly.lw.styledo.beancategoryinfo.CInfoList;

import java.util.List;

/**
 * 全局异常
 * 分类详情适配器
 * Created by T400 on 15-7-9.
 */
public class CategoryInfoAdapter extends AppBaseAdapter<CInfoList> {
    private BitmapUtils bitmapUtils;

    public CategoryInfoAdapter(List<CInfoList> list, Context context, BitmapUtils bitmapUtils) {
        super(list, context);
        this.bitmapUtils = bitmapUtils;
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder vHolder = null;
        CInfoList bean = list.get(position);
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.category_info_itemlist_layout, parent, false);
            vHolder = new ViewHolder(convertView);
            convertView.setTag(vHolder);
        } else {
            vHolder = (ViewHolder) convertView.getTag();
        }
        String imageUrl = bean.getRep_img_url();
        imageUrl = imageUrl.replace("${width}x${height}", "200x200");
        bitmapUtils.display(vHolder.image, imageUrl);

        vHolder.name.setText(bean.getPrd_nm());
        vHolder.price.setText("￥" + bean.getCeil_sel_price());
        vHolder.likeNum.setText(bean.getLike_cnt() + "");
        return convertView;
    }

    public static class ViewHolder {
        private ImageView image;
        private TextView name, price, likeNum;

        public ViewHolder(View itemView) {
            image = (ImageView) itemView.findViewById(R.id.category_info_image);
            name = (TextView) itemView.findViewById(R.id.category_info_prd_nm);
            price = (TextView) itemView.findViewById(R.id.category_info_price);
            likeNum = (TextView) itemView.findViewById(R.id.category_info_like_cnt);
        }
    }
}
